package com.ler.action;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.ide.CopyPasteManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.ler.action.util.SelectUtil;
import com.ler.action.util.XmlParser;
import java.awt.datatransfer.StringSelection;

/**
 * @author lww
 */
public class Maven2GradleAction extends AnAction {

    @Override
    public void actionPerformed(AnActionEvent e) {
        //获取当前在操作的工程上下文
        Project project = e.getData(PlatformDataKeys.PROJECT);
        String data = SelectUtil.getSelectString(e);
        if (data == null) {
            return;
        }
        try {
            String compile = XmlParser.parseXml(data);
            CopyPasteManager.getInstance().setContents(new StringSelection(compile));
            //Messages.showMessageDialog(project, "转换成功，已复制，去粘贴吧！", "Success", Messages.getInformationIcon());
        } catch (Exception ex) {
            ex.printStackTrace();
            Messages.showMessageDialog(project, "转换失败！", "Error", Messages.getInformationIcon());
        }
    }
}
